﻿using System.Web.Mvc;

namespace RefLib.MVC
{
    public sealed class AuthorizationFilter : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            bool skipAuthorization = 
                filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true) || 
                filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true);
            
            if (! skipAuthorization)
                base.OnAuthorization(filterContext);
        }
    }
}
